//
//  PrintUtil.m
//  quickBatchManager
//
//  Created by jack on 15/11/25.
//  Copyright © 2015年 jack. All rights reserved.
//

#import "PrintUtil.h"
#import "TableModel.h"
#import "PrintModel.h"
@implementation PrintUtil

+(void)printBill:(NSArray *)datas andClient:(ClientModel *)client andType:(AccountType) type andControl:(WSSessionController *)control
{
    [control closeSession];
    [control openSession];
    unsigned long encode = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    NSMutableData *printData = [[NSMutableData alloc]init];
    WSEncoder *wsAlign = [[WSEncoder alloc]init];
    [printData appendData:[wsAlign clearPrinterBuffer]];
    
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_CENTER]];
    [printData appendData:[wsAlign setFontSize:FONTSIZE_A]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_2 withHeight:TEXTHEIGHT_2]];
    [printData appendData:[wsAlign addString:client.clientName encoding:encode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"客户:%@",client.clientName] encoding:encode]];
    
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_RIGHT]];
    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"余款:%@      ",@""] encoding:encode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_CENTER]];
    NSString *line = @"------------------------------------------------------------------------------------------";
    [printData appendData:[wsAlign addString:line encoding:NSASCIIStringEncoding]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    [printData appendData:[wsAlign setLeftMarginInStandardMode:80]];
    [printData appendData:[wsAlign addString:@"日期" encoding:encode]];
    [printData appendData:[wsAlign setLeftMarginInStandardMode:300]];
    [printData appendData:[wsAlign addString:@"数量" encoding:encode]];
    [printData appendData:[wsAlign setLeftMarginInStandardMode:500]];
    [printData appendData:[wsAlign addString:@"金额" encoding:encode]];
    [printData appendData:[wsAlign setLeftMarginInStandardMode:700]];
    [printData appendData:[wsAlign addString:@"收款" encoding:encode]];
    
    [printData appendData:[wsAlign printDataInStandardMode]];
    [printData appendData:[wsAlign setLeftMarginInStandardMode:0]];
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_CENTER]];
    [printData appendData:[wsAlign addString:line encoding:NSASCIIStringEncoding]];
    [printData appendData:[wsAlign printDataInStandardMode]];

    
    
    float totalPrice = 0.0;
    float moneyReceipt = 0.0;
    for (int i=0; i<datas.count; i++) {
        if(type== AccountTypeSupplier)
        {
           
                NSObject *obj = [datas objectAtIndex:i];
                if([obj isKindOfClass:[PayOutModel class]])
                {
                    PayOutModel *outModel = (PayOutModel *)obj;
                    moneyReceipt= moneyReceipt+outModel.amount;
                    
                    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
                    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
                    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:50]];
                    [printData appendData:[wsAlign addString:outModel.payDate encoding:encode]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:300]];
                    [printData appendData:[wsAlign addString:@"-" encoding:encode]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:500]];
                    [printData appendData:[wsAlign addString:@"-" encoding:encode]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:700]];
                    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"%0.2f",outModel.amount] encoding:encode]];
                    [printData appendData:[wsAlign printDataInStandardMode]];
                }
                if([obj isKindOfClass:[BatchProductModel class]])
                {
                    BatchProductModel *batchModel = (BatchProductModel *)obj;
                    totalPrice = totalPrice+batchModel.totalPrice;
                    
                    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
                    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
                    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:50]];
                    [printData appendData:[wsAlign addString:batchModel.createDate encoding:encode]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:300]];
                    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"%0.0f",batchModel.totalNumber] encoding:encode]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:500]];
                    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"%0.2f",batchModel.totalPrice] encoding:encode]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:700]];
                    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"%0.2f",batchModel.paidPrice] encoding:encode]];
                    [printData appendData:[wsAlign printDataInStandardMode]];
                }
            
          //  [_tipLabel setText:[NSString stringWithFormat:@"金额 :%0.2f - 已支付:%0.2f",totalPrice,moneyReceipt]];
            
        }
        
        if(type== AccountTypeAllocate || type==AccountTypeClient)
        {
            
                NSObject *obj = [datas objectAtIndex:i];
                if([obj isKindOfClass:[PayInModel class]])
                {
                    PayInModel *inModel = (PayInModel *)obj;
                    moneyReceipt= moneyReceipt+inModel.amount;
                    
                    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
                    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
                    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:50]];
                    [printData appendData:[wsAlign addString:inModel.payDate encoding:encode]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:300]];
                    [printData appendData:[wsAlign addString:@"-" encoding:encode]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:500]];
                    [printData appendData:[wsAlign addString:@"-" encoding:encode]];
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:700]];
                    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"%0.2f",inModel.amount] encoding:encode]];
                    [printData appendData:[wsAlign printDataInStandardMode]];
                }
                
            
            
            
           // [_tipLabel setText:[NSString stringWithFormat:@"总金额 :%0.2f - 已收款:%0.2f - 余款:%0.2f",totalPrice,moneyReceipt,totalPrice-moneyReceipt]];
        }
        
        NSObject *obj = [datas objectAtIndex:i];
        if([obj isKindOfClass:[SaleOrderModel class]])
        {
            SaleOrderModel *orderModel = (SaleOrderModel *)obj;
            if(orderModel.isPay)
                moneyReceipt = moneyReceipt+orderModel.paidPrice;
            totalPrice = totalPrice + orderModel.totalPrice;
            
            [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
            [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
            [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
            [printData appendData:[wsAlign setLeftMarginInStandardMode:50]];
            [printData appendData:[wsAlign addString:orderModel.date encoding:encode]];
            [printData appendData:[wsAlign setLeftMarginInStandardMode:300]];
            [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"%0.0f",orderModel.totalNumber] encoding:encode]];
            [printData appendData:[wsAlign setLeftMarginInStandardMode:500]];
            [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"%0.2f",orderModel.totalPrice] encoding:encode]];
            [printData appendData:[wsAlign setLeftMarginInStandardMode:700]];
            [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"%0.2f",orderModel.paidPrice] encoding:encode]];
            [printData appendData:[wsAlign printDataInStandardMode]];
        }
        
        if([obj isKindOfClass:[ClearPriceModel class]])
        {
            ClearPriceModel *clearModel = (ClearPriceModel *)obj;
            [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
            [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
            [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
            [printData appendData:[wsAlign setLeftMarginInStandardMode:50]];
            [printData appendData:[wsAlign addString:clearModel.clearDate encoding:encode]];
            [printData appendData:[wsAlign setLeftMarginInStandardMode:300]];
            [printData appendData:[wsAlign addString:clearModel.content encoding:encode]];
            [printData appendData:[wsAlign printDataInStandardMode]];
        }
        
    }
    
    [printData appendData:[wsAlign printDataInStandardMode]];
    [printData appendData:[wsAlign setLeftMarginInStandardMode:0]];
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_CENTER]];
    [printData appendData:[wsAlign addString:line encoding:NSASCIIStringEncoding]];
    
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_RIGHT]];
    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    if(type== AccountTypeAllocate || type==AccountTypeClient)
    {
        [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"总金额 :%0.2f - 已收款:%0.2f - 余款:%0.2f       ",totalPrice,moneyReceipt,totalPrice-moneyReceipt] encoding:encode]];
    }
    if(type== AccountTypeSupplier)
    {
        [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"总金额 :%0.2f - 已支付:%0.2f       ",totalPrice,moneyReceipt] encoding:encode]];
    }
    
    
    
    [printData appendData:[wsAlign printDataInStandardMode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    [printData appendData:[wsAlign printDataInStandardMode]];

    
     [control writeData:printData];

}


+(void)printOrder:(SaleOrderModel *)model andControl:(WSSessionController *)control
{
    [control closeSession];
    [control openSession];
    NSMutableArray *batchlist=[[NSMutableArray alloc] init];
    [batchlist addObject:[ToolUtils numberToStr:model.saleOrderId]];
    
    
    NSMutableArray *tlist=[[NSMutableArray alloc] init];
    NSArray *plist=[SaleOrderInfoModel searchWithWhere:@{@"saleOrderId":batchlist} orderBy:nil groupBy:@"productId" offset:0 count:0];
    
    NSArray *datalist;
    datalist=tlist;
    
    for (SaleOrderInfoModel *data in plist) {
        NSMutableArray *p1=[[NSMutableArray alloc] init];
        TableModel *model=[[TableModel alloc] init];
        model.tableList=p1;
        model.modelTitle=data.product.modelNo;
        model.totalTitle=[NSString stringWithFormat:@"￥ %0.1f元 计：%0.f",[SaleOrderInfoModel sumWithWhere:@"productNumber*price" where:@{@"saleOrderId":batchlist,@"productId":[ToolUtils numberToStr:data.productId]}],[SaleOrderInfoModel sumWithWhere:@"productNumber" where:@{@"saleOrderId":batchlist,@"productId":[ToolUtils numberToStr:data.productId]}]];
        model.productNumber = [SaleOrderInfoModel sumWithWhere:@"productNumber" where:@{@"saleOrderId":batchlist,@"productId":[ToolUtils numberToStr:data.productId]}];
        [tlist addObject:model];
        
        
        NSDictionary *colorsizeDic=[AppService getSizeAndColorByModel:data.product.modelNo];
        
        NSArray *sizeList=colorsizeDic[@"size"];
        NSArray *colorList=colorsizeDic[@"color"];
        
        for (int i=0; i<=colorList.count; i++) {
            
            NSMutableArray *p2=[[NSMutableArray alloc] init];
            [p1 addObject:p2];
            for (int j=0; j<=sizeList.count; j++)
            {
                if(i==0 && j==0)
                {
                    [p2 addObject:@"颜色"];
                }
                else if(i==0)
                {
                    [p2 addObject:[sizeList objectAtIndex:j-1]];
                }
                else if(j==0)
                {
                    [p2 addObject:[colorList objectAtIndex:i-1]];
                }
                else  {
                    NSString *num = [ToolUtils numberToStr:[SaleOrderInfoModel sumWithWhere:@"productNumber" where:@{@"saleOrderId":batchlist,@"productId":[ToolUtils numberToStr:data.productId],@"sizeName":[sizeList objectAtIndex:j-1],@"colorName":[colorList objectAtIndex:i-1]}]];
                    NSLog(@"num:%@ colorName:%@ sizeName:%@",num,[colorList objectAtIndex:i-1],[sizeList objectAtIndex:j-1]);
                    [p2 addObject:num];
                }
            }
        }
        
    }
    
    
    //打印
    unsigned long encode = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    NSMutableData *printData = [[NSMutableData alloc]init];
    WSEncoder *wsAlign = [[WSEncoder alloc]init];
    
    [printData appendData:[wsAlign clearPrinterBuffer]];
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
    [printData appendData:[wsAlign addString:@"客户联" encoding:encode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_CENTER]];
    [printData appendData:[wsAlign setFontSize:FONTSIZE_A]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_2 withHeight:TEXTHEIGHT_2]];
    [printData appendData:[wsAlign addString:model.client.clientName encoding:encode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    //客户名单号
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"客户:%@",model.client.clientName] encoding:encode]];
    
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_RIGHT]];
    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"No:%@",model.saleOrderNo] encoding:encode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    //电话日期
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"电话:%@",model.mobile] encoding:encode]];
    
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_RIGHT]];
    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"%@",model.date] encoding:encode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_CENTER]];
    NSString *line = @"==========================================================================================";
    [printData appendData:[wsAlign addString:line encoding:NSASCIIStringEncoding]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
    
    
    //产品信息
    int total = 0;
    float totalM=0;
    for (int i=0; i<[datalist count]; i++) {
        TableModel *tableModel = [datalist objectAtIndex:i];
        total = total+tableModel.productNumber;
        ProductModel *product = [ProductModel searchSingleWithWhere:[NSString stringWithFormat:@"modelNo=%@",tableModel.modelTitle] orderBy:nil];
        totalM = totalM +tableModel.productNumber*product.salePrice;
        NSArray *list = tableModel.tableList;
        if(list && [list count])
        {
            for (int j=0; j<[list count]; j++) {
                NSArray *rowData=list[j];
                for (int z=0; z<rowData.count; z++) {
                    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
                    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
                    if(z==0 && j==0)
                    {
                        [printData appendData:[wsAlign addString:tableModel.modelTitle encoding:encode]];
                    }else
                    {
                        NSString *str = [rowData objectAtIndex:z];
                        [printData appendData:[wsAlign addString:str encoding:encode]];
                    }
                    
                    int margin = 100*(z+1);
                    [printData appendData:[wsAlign setLeftMarginInStandardMode:margin]];
                    
                }
                
                [printData appendData:[wsAlign printDataInStandardMode]];
                [printData appendData:[wsAlign setLeftMarginInStandardMode:0]];
                
            }
            [printData appendData:[wsAlign printDataInStandardMode]];
            [printData appendData:[wsAlign setLeftMarginInStandardMode:0]];
            //合计
            [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
            [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
            [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_RIGHT]];
            NSString *str = [NSString stringWithFormat:@"共%0.0f件 X %0.1f 计:%0.1f    ",tableModel.productNumber,product.salePrice,tableModel.productNumber*product.salePrice];
            [printData appendData:[wsAlign addString:str encoding:encode]];
            [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
            [printData appendData:[wsAlign printDataInStandardMode]];
            
            
            
            
        }
    }
    
    
    [printData appendData:[wsAlign printDataInStandardMode]];
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_CENTER]];
    NSString *line2 = @"------------------------------------------------------------------------------------------";
    [printData appendData:[wsAlign addString:line2 encoding:NSASCIIStringEncoding]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    
    
    //共
    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    NSString *totalTitle = [NSString stringWithFormat:@"共%lu款 计:%d件    ",(unsigned long)datalist.count,total];
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_RIGHT]];
    [printData appendData:[wsAlign addString:totalTitle encoding:encode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    //总金额
    [printData appendData:[wsAlign setFontSize:FONTSIZE_A]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_2 withHeight:TEXTHEIGHT_2]];
    NSString *totalMoney = [NSString stringWithFormat:@"总金额:%0.2f",totalM];
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_RIGHT]];
    [printData appendData:[wsAlign addString:totalMoney encoding:encode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    //付款信息
    [printData appendData:[wsAlign setFontSize:FONTSIZE_A]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_2 withHeight:TEXTHEIGHT_2]];
    if(model.isPay)
    {
         NSArray *paylist=[[CoreArchive strForKey:NSDEFAULT_ST_PAYMENT] componentsSeparatedByString:@"|"];
        NSString *payType = [paylist objectAtIndex:[model.payType integerValue]];
        NSString *totalMoney = [NSString stringWithFormat:@"%@:%0.2f",payType,totalM];
        [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_RIGHT]];
        [printData appendData:[wsAlign addString:totalMoney encoding:encode]];
        [printData appendData:[wsAlign printDataInStandardMode]];
    }else
    {
        [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_RIGHT]];
        [printData appendData:[wsAlign addString:@"未付款" encoding:encode]];
        [printData appendData:[wsAlign printDataInStandardMode]];
    }
    
    
    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_CENTER]];
    [printData appendData:[wsAlign addString:line encoding:NSASCIIStringEncoding]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    
    //打印备注
    [printData appendData:[wsAlign setTextAlignInStandardMode:ALIGN_LEFT]];
    [printData appendData:[wsAlign setFontSize:FONTSIZE_B]];
    [printData appendData:[wsAlign setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    [printData appendData:[wsAlign addString:[NSString stringWithFormat:@"备注:%@",model.remark] encoding:encode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    [printData appendData:[wsAlign printDataInStandardMode]];
    
    //打印二维码
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    BOOL isQR = [defaults boolForKey:@"isQR"];
    if(isQR)
    {
        PrintModel *model = [PrintModel searchSingleWithWhere:@"isSelect=1" orderBy:nil];
//        NSData* responseData = [model.content dataUsingEncoding:NSUTF8StringEncoding];
//        NSString *responseString = [[NSString alloc] initWithData:responseData encoding:encode];
        [printData appendData:[wsAlign enableHRI:NO]];
        [printData appendData:[wsAlign addString:@"QR-Code Barcode\r\n" encoding:NSASCIIStringEncoding]];
        [printData appendData:[wsAlign createBarcodeQRCode:model.content symbolVersion:0 ECLevel:'M' moduleSize:5]];
        [printData appendData:[wsAlign printAndFeedNLineInStandardMode:1]];
        [printData appendData:[wsAlign printDataInStandardMode]];
        [printData appendData:[wsAlign printDataInStandardMode]];
        [printData appendData:[wsAlign printDataInStandardMode]];
        [printData appendData:[wsAlign printDataInStandardMode]];
    }
    
    
    
    
    [control writeData:printData];

    

}
@end
